#ifndef __INFRA_COMM_H__
#define __INFRA_COMM_H__

#include <stdio.h>

#ifdef __cplusplus
extern "C" {
#endif

#define INFRA_TOKEN_MAX_SIZE    (32)
#define TO_STRING(x)            #x

#define infra_err(fmt, ...)          printf("[E][%24s][%4d]: "fmt, __FUNCTION__, __LINE__, ##__VA_ARGS__)
#define infra_warn(fmt, ...)         printf("[W][%24s][%4d]: "fmt, __FUNCTION__, __LINE__, ##__VA_ARGS__)
#define infra_info(fmt, ...)         printf("[I][%24s][%4d]: "fmt, __FUNCTION__, __LINE__, ##__VA_ARGS__)
#define infra_dbg(fmt, ...)          printf("[D][%24s][%4d]: "fmt, __FUNCTION__, __LINE__, ##__VA_ARGS__)

#define INFRA_PTR_CHECK(ptr)                                \
do {                                                        \
    if (NULL == ptr) {                                      \
        infra_err("%s is NULL\n", TO_STRING(ptr));          \
        return -1;                                          \
    }                                                       \
} while (0)

#define INFRA_PTR_CHECK_STR(ptr, str)                       \
do {                                                        \
    if (NULL == ptr) {                                      \
        infra_err("%s is NULL, %s\n", TO_STRING(ptr), str); \
        return -1;                                          \
    }                                                       \
} while (0)

#ifdef __cplusplus
}
#endif

#endif /* __INFRA_COMM_H__ */